package com.dajiangtai.djt_spider.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.dajiangtai.djt_spider.util.PageDownLoadUtil;
import com.dajiangtai.djt_spider.util.RegexUtil;

/**
 * 存储页面信息实体类
 * @author dajiangtai
 * created by 2016-10-28
 *
 */
public class Page {
	//页面内容
	private String content;
	//总播放量
	private String allnumber;
	//每日播放增量
	private String daynumber;
	//评论数
	private String commentnumber;
	//收藏数
	private String collectnumber;
	//赞
	private String supportnumber;
	//踩
	private String againstnumber;
	
	//电视剧名称
	private String tvname;
	//页面url
	private String url;
	//子集数据
	private String episodenumber;
	
	//电视剧id
	private String tvId;
	
	public static void main(String[] args) throws Exception {
		String url="http://tv.youku.com/search/index/_page40177_1_cmodid_40177?spm=a2htv.20005143.m13050845531.5%212~5~1~3%215~A";
		Page page=new Page();
		url="http://index.youku.com/ProAction!getProVideos.action?proId=69cc4c7647d811e5a080&pageIndex=3&pageSize=10&type=main&tag=youku";
		url="http://index.youku.com/ProAction!getProVideos.action?proId=6a4d7c5aab1d11e6b9bb&pageIndex=0&pageSize=10&type=main&tag=youku";
		System.out.println(PageDownLoadUtil.getPageContent(url));
		
		if(url.startsWith("http://tv.youku.com/search/index/")){
			Document doc = Jsoup.parse(PageDownLoadUtil.getPageContent(url));
			String nextURL=doc.select("div.next a").attr("href");
			page.addUrl(nextURL);
			Elements eles = doc.select("ul.p");
			for (Element each : eles) {
				String tvurl=each.select("li.p_link a").attr("href");
				page.addUrl(tvurl);
			}
		}else if(url.startsWith("http://www.youku.com/show_page/")){
			Document doc2 = Jsoup.parse(PageDownLoadUtil.getPageContent(url));
			String totalNum=doc2.getElementsContainingOwnText("总播放数").text().replace("总播放数：", "").replace(",", "");
			String comNum=doc2.getElementsContainingOwnText("评论").text().replace("评论：", "").replace(",", "");
			String dingNum=doc2.getElementsContainingOwnText("顶").text().replace("顶：", "").replace(",", "");
			System.out.println("totalNum:"+totalNum);
			System.out.println("comNum:"+comNum);
			System.out.println("dingNum:"+dingNum);
			page.setAllnumber(totalNum);
			page.setCommentnumber(comNum);
			page.setSupportnumber(dingNum);
		}
	}
	
	//存储电视剧url（包含列表url和详情页url）
	private List<String> urlList = new ArrayList<String>();
	
	public String getTvId() {
		return tvId;
	}
	public void setTvId(String tvId) {
		this.tvId = tvId;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getAllnumber() {
		return allnumber;
	}
	public void setAllnumber(String allnumber) {
		this.allnumber = allnumber;
	}
	public String getCommentnumber() {
		return commentnumber;
	}
	public void setCommentnumber(String commentnumber) {
		this.commentnumber = commentnumber;
	}
	public String getSupportnumber() {
		return supportnumber;
	}
	public void setSupportnumber(String supportnumber) {
		this.supportnumber = supportnumber;
	}
	public String getTvname() {
		return tvname;
	}
	public void setTvname(String tvname) {
		this.tvname = tvname;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getEpisodenumber() {
		return episodenumber;
	}
	public void setEpisodenumber(String episodenumber) {
		this.episodenumber = episodenumber;
	}
	public List<String> getUrlList() {
		return urlList;
	}
		
	public void addUrl(String url){
		this.urlList.add(url);
	}
	public String getDaynumber() {
		return daynumber;
	}
	public void setDaynumber(String daynumber) {
		this.daynumber = daynumber;
	}
	public String getCollectnumber() {
		return collectnumber;
	}
	public void setCollectnumber(String collectnumber) {
		this.collectnumber = collectnumber;
	}
	public String getAgainstnumber() {
		return againstnumber;
	}
	public void setAgainstnumber(String againstnumber) {
		this.againstnumber = againstnumber;
	}
	public void setUrlList(List<String> urlList) {
		this.urlList = urlList;
	}
	
	
}
